package Railroad.Components;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class OperatorStation extends TrackItem {
    public final int posX, posY;
    public final Date dayStart, dayEnd;
    public final boolean up;

    public OperatorStation(int id, int posX, int posY, Date dayStart, Date dayEnd, boolean up) {
        super(id);
        this.posX = posX;
        this.posY = posY;
        this.dayStart = dayStart;
        this.dayEnd = dayEnd;
        this.up = up;
    }

    @Override
    public boolean isOnXY(int x, int y) {
        return x == posX && y == posY;
    }
    
    public boolean isDay(Date current) {
        try {
            SimpleDateFormat f = new SimpleDateFormat("HH:mm");
            Date currentTime = f.parse(f.format(current));  // hack-fix to ignore the day portion of the current time
            return currentTime.compareTo(dayStart) >= 0 &&
                    currentTime.compareTo(dayEnd) <= 0;
        } catch (ParseException ex) {
            return true;
        }
    }
}
